package com.beibei.framework.logger;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.LogManager;

/**
 * 获取Logger对象的工厂类
 * 
 * @author: 309814490@qq.com
 * @version: 2014-02-12
 */
public class LoggerFactory {
	private static Map<String, Map<String, LoggerDefaultImpl>> loggers = new HashMap<String, Map<String, LoggerDefaultImpl>>();

	public static ILogger getCommonLog(Class<?> clz) {
		return getLogger(LoggerType.COMMON, getClassName(clz));
	}

	public static ILogger getPageLog() {
		return getLogger(LoggerType.PAGE, LoggerType.PAGE);
	}

	public static ILogger getJdbcLog() {
		return getLogger(LoggerType.JDBC, LoggerType.JDBC);
	}

	public static ILogger getServiceLog() {
		return getLogger(LoggerType.SERVICE, LoggerType.SERVICE);
	}

	public static ILogger getLogger(String type, String id) {
		if (!(loggers.containsKey(type)))
			loggers.put(type, new HashMap<String, LoggerDefaultImpl>());

		Map<String, LoggerDefaultImpl> logger = loggers.get(type);
		if (!(logger.containsKey(type)))
			logger.put(type,
					new LoggerDefaultImpl(type, LogManager.getLogger(id)));

		return logger.get(type);
	}

	private static String getClassName(Class<?> clz) {
		return clz.getName();
	}

}